<template>
  <div id="SellCart">
    <div class="sellcart-left" @click="mSwitchTop()">
      <div class="iconColorHover">
        <div class="Great">
          <div class="circle">
            <i class="iconfont icon-gouwuche"></i>
            <span v-show="totalCount" class="count">{{ totalCount }}</span>
          </div>
        </div>
      </div>
      <span v-if="totalPrice == 0 ? false : true" class="Price">￥{{ totalPrice }}</span>
      <span v-else>未选购商品</span>
    </div>
    <div class="sellcart-right">
      <span>￥20起送</span>
    </div>
    <transition name="slide">
      <div class="mask" v-show="flage" @click="mSwitchTop()">
        <div class="info" @click.stop>
          <div class="title">
            <div class="infos">已选商品</div>
            <div class="clear">清空</div>
          </div>
          <div class="content">
            <div v-for="food in selectedGoods" :key="food.id" class="item">
              <div class="name">{{ food.name }}</div>
              <div class="price">￥{{ food.price }}</div>
              <!-- 控制按钮 -->
              <van-stepper
                @click.native.stop
                min="0"
                class="control"
                v-model="food.count"
                theme="round"
                button-size="20"
                disable-input
              />
            </div>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
  data () {
    return {
      flage: false,
      isAni: false
    }
  },
  watch: {
    totalCount (newVal, oldVal) {
      if (newVal > oldVal) {
        this.isAni = true
      }
    }
  },
  computed: {
    ...mapGetters(['selectedGoods']),
    totalCount (content) {
      let total = 0
      content.selectedGoods.forEach(food => {
        total += food.count

      })
      return total
    },
    totalPrice (content) {
      let sum = 0
      content.selectedGoods.forEach(food => {
        sum += food.count * food.price
      })
      return sum.toFixed(2)
    }
  },
  methods: {
    mSwitchTop () {
      this.flage = !this.flage
    }
  },
}
</script>

<style lang="less" scoped>
#SellCart {
  display: flex;
  position: relative;
  .sellcart-left {
    position: relative;
    z-index: 1;
    flex: 1;
    background-color: #131d29;
    color: #7a8189;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    .iconColorHover {
      position: absolute;
      left: 20px;
      top: -25px;
      .Great {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #131d29;
        .circle {
          position: relative;
          width: 50px;
          height: 50px;
          border-radius: 50%;
          display: flex;
          justify-content: center;
          align-items: center;
          background-color: #2c333d;
          .iconfont {
            font-size: 35px;
          }
          .count{
            position: absolute;
            top: 5px;
            right: 5px;
            color: white;
            padding: 3px;
            border-radius: 50%;
            overflow: hidden;
            font-size: 10px;
            background-color: red;
          }
        }
      }
    }
    .Price{
      color: red;
      font-weight: 700;
      font-size: 24px;
    }
  }
  .sellcart-right {
    position: relative;
    z-index: 1;
    width: 120px;
    height: 100%;
    background-color: #2c333b;
    color: #7a8189;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .mask {
    position: fixed;
    bottom: 70px;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    .info {
      position: absolute;
      bottom: 0;
      background-color: white;
      width: 100%;
      height: 400px;
      overflow:auto;
      .title {
        padding: 0 15px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 50px;
        color: #333;
        background: #edeef2;
      }
      .content {
        box-sizing: border-box;
        padding: 0 15px;
        .item {
          position: relative;
          z-index: 5;
          height: 60px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1px solid #ccc;
          .name {
            width: 200px;
            font-weight: 700;
          }
          .price {
            color: red;
          }
          .control {
            bottom: 0px;
            right: 5px;
            /deep/.van-stepper__input {
              width: 20px;
            }
            /deep/.van-stepper__plus {
              background-color: #009de3;
            }
            /deep/.van-stepper__minus {
              color: #009de3;
              border: 1px solid #009de3;
            }
          }
        }
      }
    }
  }
  .slide-enter-active,
  .slide-leave-active {
    transition: all 0.3s;
  }
  .slide-enter,
  .slide-leave-to {
    transform: translateY(100%);
  }
}
</style>